package com.hexb.smh.entity.enums;

import com.hexb.smh.entity.param.account.AccountParam;
import com.hexb.smh.entity.param.config.ConfigParam;
import com.hexb.smh.entity.param.config.EvaluateParam;
import com.hexb.smh.entity.param.product.ProductParam;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author : hexb
 */
public enum Operators {
    none(args -> ""),
    activeAccount(args -> "首次登录重设密码"),
    appendAccount(args -> {
        AccountParam.AccountParamInsert param = (AccountParam.AccountParamInsert) args[0];
        return String.format("添加帐号[%s,%s,%s]",
                param.getName(),
                param.getLoginName(),
                param.getPhoneNo());
    }),
    updateAccount(args -> {
        AccountParam.AccountParamUpdate param = (AccountParam.AccountParamUpdate) args[1];
        return String.format("编辑帐号(:id=%s)[%s,%s]",
                args[0],
                param.getName(),
                param.getPhoneNo());
    }),
    deleteAccount(args -> {
        return String.format("注销帐号:[%s]", args[0]);
    }),
    enableAccount(args -> {
        return String.format("启用帐号:[%s]", args[0]);
    }),
    disableAccount(args -> {
        return String.format("禁用帐号:[%s]", args[0]);
    }),
    resetPassword(args -> {
        return String.format("重置帐号:[%s]密码为默认密码", args[0]);
    }),
    batchDeleteAccount(args -> {
        Integer[] ids = (Integer[]) args[0];
        return String.format("注销多个帐号:[%s]", Arrays.stream(ids).map(String::valueOf).collect(Collectors.joining(",")));
    }),
    batchEnableAccount(args -> {
        Integer[] ids = (Integer[]) args[0];
        return String.format("启用多个帐号:[%s]", Arrays.stream(ids).map(String::valueOf).collect(Collectors.joining(",")));
    }),
    batchDisableAccount(args -> {
        Integer[] ids = (Integer[]) args[0];
        return String.format("禁用多个帐号:[%s]", Arrays.stream(ids).map(String::valueOf).collect(Collectors.joining(",")));
    }),

    appendProduct(args -> {
        ProductParam.ProductParamInsert param = (ProductParam.ProductParamInsert) args[0];
        return String.format("添加项目[%s,%s,%s]",
                param.getName(),
                param.getItemNo(),
                param.getBriefCode()
        );
    }),
    updateProduct(args -> {
        ProductParam.ProductParamUpdate param = (ProductParam.ProductParamUpdate) args[0];
        return String.format("编辑项目(:id=%s)[%s,%s,%s]",
                args[0],
                param.getName(),
                param.getItemNo(),
                param.getBriefCode());
    }),
    deleteProduct(args -> {
        return String.format("删除项目:[%s]", args[0]);
    }),
    toggleProduct(args -> {
        Boolean activated = (Boolean) args[1];
        return String.format("%s:[%s]", activated ? "上架项目" : "下架项目", args[0]);
    }),
    batchDeleteProduct(args -> {
        Integer[] ids = (Integer[]) args[0];
        return String.format("删除多个项目:[%s]", Arrays.stream(ids).map(String::valueOf).collect(Collectors.joining(",")));
    }),
    batchToggleProduct(args -> {
        Integer[] ids = (Integer[]) args[0];
        Boolean activated = (Boolean) args[1];
        return String.format("%s多个项目:[%s]", activated ? "上架" : "下架", Arrays.stream(ids).map(String::valueOf).collect(Collectors.joining(",")));
    }),

    saveConfig(args -> {
        ConfigParam param = (ConfigParam) args[0];
        return String.format("保存配置[%s=%s]", param.getType().getLabel(), param.getValue());
    }),

    evaluate(args -> {
        EvaluateParam param = (EvaluateParam) args[0];
        return String.format("评估套餐[项目:(%s),成交价:%s]",
                Arrays.stream(param.getIds()).map(String::valueOf).collect(Collectors.joining(",")),
                param.getDealPrice());
    });


    final private ILogCreator creator;

    Operators(ILogCreator creator) {
        this.creator = creator;
    }

    public ILogCreator getCreator() {
        return creator;
    }
}
